package com.ecmcloud.resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ecmcloud.common.config.NotWriteLogAnno;
import com.ecmcloud.common.dto.MessageDto;
import com.ecmcloud.common.dto.Result;
import com.ecmcloud.entity.Message;
import com.ecmcloud.service.IMessageService;

import lombok.SneakyThrows;

/**
 * 消息控制器
 */
@RestController
@RequestMapping(value = {"message", "api/message"})
public class MessageResource {

	@Autowired
    private IMessageService messageService;

    /**
     * 未读数量
     */
    @SneakyThrows
    @NotWriteLogAnno(printResultLog = false)
    @GetMapping("unreadNum")
    public Result<Long> queryUnreadNum() {
        return messageService.queryUnreadNum();
    }

    /**
     * 查询列表
     *
     * @param pageDto
     * @return
     */
    @PostMapping("queryList")
    public Result<Page<Message>> queryList(@RequestBody MessageDto pageDto) {
        return messageService.queryList(pageDto);
    }

    /**
     * 删除消息
     *
     * @param messageDto
     * @return
     */
    @DeleteMapping("delete")
    public Result<String> delete(@RequestBody MessageDto messageDto) {
        return messageService.delete(messageDto);
    }

    /**
     * 置为已读
     *
     * @param messageDto
     * @return
     */
    @PostMapping("read")
    public Result<String> read(@RequestBody MessageDto messageDto) {
        return messageService.read(messageDto);
    }


}
